<template>
  <div class="userList">
    <el-table
        :data="items"
        stripe
        style="width: 100%">
      <el-table-column
          prop="id"
          label="ID"
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="昵称"
          width="180">
      </el-table-column>
      <el-table-column
          prop="mail"
          label="邮箱"
          width="180">
      </el-table-column>
      <el-table-column
          prop="phone"
          width="180"
          label="电话">
      </el-table-column>
      <el-table-column
          prop="avatar"
          label="头像">
        <template slot-scope="scope">
<!--          <p>{{scope.row.avatar}}</p>-->
          <el-avatar lazy fit="contain"   :src="baseUrl+scope.row.avatar" class="mt10" size="large"></el-avatar>
        </template>

      </el-table-column>

      <el-table-column           width="250"
                                 label="操作">
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="editUser( scope.row)">编辑</el-button>
          <el-button
              size="mini"
              type="danger"
              @click="banUser( scope.row)">封号</el-button>
          <el-button
              size="mini"
              type="danger"
              @click="deleteUser(scope.row)">删除</el-button>
        </template>
      </el-table-column>


    </el-table>
  </div>
</template>

<script>
import user from "@/api/user";
import service from "@/api";


export default {
  name: "UserList",
  data() {
    return{
      baseUrl:service.imageURL,
      items: [],
      query: {},
    }
  },
  created() {

    // if (this.$store.state.user.role!=='admin'){
    //   this.$router.push({path:'/home'});
    // }

    this.getData()
  },
  methods:{
    getData() {
     user.getUsers().then(res=>{
       this.items = res.data
     })
    },
    addUser(row){},
    // addUser(row){},
    editUser(row){
      this.$router.push({path:"/userEdit?id="+row.id,});

    },
    deleteUser(row){



      this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {


        user.deleteUser(row.id).then(res=>{

          console.log(res)

          if (res.data===true){

            this.$message({
              type: 'success',
              message: '删除成功!'
            });

            this.getData()
          }else{

            this.$message({
              type:'error',
              message: '删除失败'
            });
          }
        })
      }).catch((e) => {
        console.log(e)
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });



    },

    banUser(row){

    },
  }
}
</script>

<style lang="scss" scoped>

.userList{
  width: 95%;
  margin: 0 auto;
}

</style>
